package com.edu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.bean.Book;
import com.edu.bean.Page;
import com.edu.service.BookService;
import com.edu.service.impl.BookServiceImpl;

@WebServlet("/Book.do")
public class SeachBookServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		BookService bks=new BookServiceImpl();
		int pageNum=0;
		int pageSize=0;
		int rows=bks.serachBookRows();
		try {
			pageSize = Integer.parseInt(req.getParameter("pageSize"));
		} catch (Exception e) {
			pageSize = 5;
		}
		
		try {
			pageNum = Integer.parseInt(req.getParameter("pageNum"));
		} catch (Exception e) {
			pageNum = 1;
		}

		List<Book> bookList=bks.selectAllbook(pageNum,pageSize);
		Page<Book> page=new Page(bookList,pageNum,pageSize,rows);
		
		if(page!=null) {
			req.setAttribute("page", page);
			req.getRequestDispatcher("book.jsp").forward(req, resp);
		}
	}
}
